<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "area".
 *
 * @property int $id
 * @property int $parent_id 父级ID
 * @property int $level 层级
 * @property string $area_code 行政代码
 * @property int $zip_code 邮政编码
 * @property string $city_code 区号
 * @property string $name 名称
 * @property string $short_name 简称
 * @property string $merger_name 组合名
 * @property string $pinyin 拼音
 * @property string $lng 经度
 * @property string $lat 纬度
 */
class Area extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'area';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['parent_id', 'level', 'area_code', 'zip_code'], 'integer'],
            [['lng', 'lat'], 'number'],
            [['city_code'], 'string', 'max' => 6],
            [['name', 'short_name', 'merger_name'], 'string', 'max' => 50],
            [['pinyin'], 'string', 'max' => 30],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'parent_id' => '父级ID',
            'level' => '层级',
            'area_code' => '行政代码',
            'zip_code' => '邮政编码',
            'city_code' => '区号',
            'name' => '名称',
            'short_name' => '简称',
            'merger_name' => '组合名',
            'pinyin' => '拼音',
            'lng' => '经度',
            'lat' => '纬度',
        ];
    }

    public function getParentArea(){
        return $this->hasOne(Area::class, ['id' => 'parent_id']);
    }
}
